var GameMessageRouter = 'game.gameHandler.gameMessageNotify';
var DGNProto           = require('./DGNProto');
var DGNModel           = require('./DGNModel');
cc.Class({
	extends: cc.Component,
	properties: {
	},

	onLoad: function () {
		this.scoreLabel = cc.find("Label", this.node).getComponent(cc.Label);
		this.slider = cc.find("Slider", this.node).getComponent(cc.Slider);
		this.progressBar = cc.find("ProgressBar", this.node).getComponent(cc.ProgressBar);
	},

	showSelf: function () {
		this.node.active = true;
		this.range = DGNModel.getPourScoreRange();
		this.scoreLabel.string = ""+this.range[0]; 
		this.slider.progress = 0;
		this.progressBar.progress = 0;
	},

	onSlider: function (event, param) {
		this.progressBar.progress = this.slider.progress;
		var score = Math.floor((this.range[1]-this.range[0])*this.slider.progress+this.range[0]);
		this.scoreLabel.string = ""+score;
	},

	onButton: function (event, param) {
        Global.AudioManager.playCommonSoundClickButton();
		if (param == "xiazhu") {
			let score = parseInt(this.scoreLabel.string);
			if (!isNaN(score) && score > 0) {
				this.node.active = false;
				Global.NetworkManager.notify(GameMessageRouter, DGNProto.pourScoreNotify(score, false));
			}
		}
		else if (param == "shemen") {
			let score = this.range[1];
			this.node.active = false;
			Global.NetworkManager.notify(GameMessageRouter, DGNProto.pourScoreNotify(score, true));
			Global.AudioManager.playSound('Game/Niuniu/NNAudio/shemen');
		}
	},
});
